package com.ley.springboot.commons.utils;


import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger utility class
 *
 * @author 2036185346@qq.com
 **/
public class SwaggerUtils {

    /**
     * swagger api title
     **/
    private static String projectSwaggerApiTitle="";

    /**
     * project swagger api version
     **/
    private static String projectSwaggerApiVersion="";

    private static ApiInfo apiInfo() {
        return (new ApiInfoBuilder()).title(SwaggerUtils.projectSwaggerApiTitle).version(SwaggerUtils.projectSwaggerApiVersion).build();
    }

    public static void setProjectSwaggerApiTitle(String projectSwaggerApiTitle) {
        SwaggerUtils.projectSwaggerApiTitle = projectSwaggerApiTitle;
    }

    public static void setProjectSwaggerApiVersion(String projectSwaggerApiVersion) {
        SwaggerUtils.projectSwaggerApiVersion = projectSwaggerApiVersion;
    }

    /**
     * init {@link Docket}
     **/
    public static Docket initDocket() {
        return (new Docket(DocumentationType.SWAGGER_2)).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
    }
}
